import {MessageBox} from "element-ui";
import router from "@/router";

export let handleError = function (err) {
    //报错第一件事就是清除dom
    let res = err?.response?.data?.results || err || '未知错误！'
    document.querySelector('#app').style.display = 'none'
    MessageBox.alert(res.message, res.code, {
        confirmButtonText: '确定',
        title: '错误提示！',
        type: 'error',
        showClose: false,
        lockScroll: true,
    }).then(() => {
        //如果重复登录会无限添加 在导航守卫中采取措施
        router.replace({
            path: '/login',
            query: {redirect: router.currentRoute.fullPath || ''}
        }).then(route => {
            document.querySelector('#app').style.display = 'block'
            console.log('401通过跳转，', route)
        })
    })
    return res
}
